import java.time.LocalDateTime;
import java.util.List;

public class ShowService {
    private ShowDao showDao = new ShowDaoImpl();
    private int showIdCounter = 1;

    // 自动排片
    public void autoArrangeShows(List<Movie> movies, List<Hall> halls) {
        LocalDateTime baseTime = LocalDateTime.now().plusHours(1); // 1小时后开始

        for (Movie movie : movies) {
            for (Hall hall : halls) {
                // 每天排3场：10:00、15:00、19:00
                for (int day = 0; day < 3; day++) { // 排未来3天的场次
                    for (int hour : new int[]{10, 15, 19}) {
                        LocalDateTime showTime = baseTime.plusDays(day)
                                                       .withHour(hour)
                                                       .withMinute(0)
                                                       .withSecond(0);
                        
                        // 根据评分设置票价
                        double price = movie.getScore() > 8.0 ? 60.0 : 45.0;
                        
                        Show show = new Show(
                            "S" + String.format("%03d", showIdCounter++),
                            movie,
                            hall,
                            showTime,
                            price
                        );
                        
                        showDao.addShow(show);
                    }
                }
            }
        }
        System.out.println("自动排片完成，新增" + (showIdCounter - 1) + "场电影");
    }

    // 获取所有场次
    public List<Show> getAllShows() {
        return showDao.getAllShows();
    }

    // 根据ID获取场次
    public Show getShowById(String showId) {
        return showDao.getShowById(showId);
    }
}
    